package com.xasqkj.seethedoctorwithphone.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

import com.xasqkj.seethedoctorwithphone.R;
import com.xasqkj.seethedoctorwithphone.adapter.Myadapter;
import com.zhy.android.percent.support.PercentLinearLayout;

/**
 * Created by YixuanNan on 16/4/7.
 */
public class MainFragment extends Fragment implements View.OnClickListener {
    private static final String RidTag = "Rid";
    private PercentLinearLayout linearLayoutWenZhen;
    private FragmentPropertyManager fragmentPropertyManager;
    private Button btn1, btn2, btn3, btn4, btn5;

    public MainFragment() {

    }

    public static MainFragment newInstance(int Rid) {
        MainFragment fragment = new MainFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(RidTag, Rid);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getArguments().getInt(RidTag), null);
        fragmentPropertyManager = new FragmentPropertyManager(getActivity());
        if (getArguments().getInt(RidTag) == R.layout.fragment_main) {
            linearLayoutWenZhen = (PercentLinearLayout) view.findViewById(R.id.linearlayoutWenZhen);
            linearLayoutWenZhen.setOnClickListener(this);
            PercentLinearLayout linearLayoutShiPinYiSheng = (PercentLinearLayout) view.findViewById(R.id.linearlayoutShiPinYiSheng);
            linearLayoutShiPinYiSheng.setOnClickListener(this);
            PercentLinearLayout linearLayoutXueKePu = (PercentLinearLayout) view.findViewById(R.id.linearlayoutXueKePu);
            linearLayoutXueKePu.setOnClickListener(this);
        }
        if (getArguments().getInt(RidTag) == R.layout.fragment_wenzhen) {
            btn1 = (Button) view.findViewById(R.id.btn1);
            btn1.setOnClickListener(this);
            btn2 = (Button) view.findViewById(R.id.btn2);
            btn2.setOnClickListener(this);
            btn3 = (Button) view.findViewById(R.id.btn3);
            btn3.setOnClickListener(this);
            btn4 = (Button) view.findViewById(R.id.btn4);
            btn4.setOnClickListener(this);
            btn5 = (Button) view.findViewById(R.id.btn5);
            btn5.setOnClickListener(this);
        }
        if (getArguments().getInt(RidTag) == R.layout.fragment_zhengzhuangxuanze) {
            linearLayoutWenZhen = (PercentLinearLayout) view.findViewById(R.id.xuanze_lin1);
            linearLayoutWenZhen.setOnClickListener(this);
        }
        if (getArguments().getInt(RidTag) == R.layout.fragment_shipinyisheng) {
            ListView listView = (ListView) view.findViewById(R.id.lv);
            listView.setAdapter(new Myadapter(getActivity(),R.layout.listview_shipinyisheng));
        }
        if (getArguments().getInt(RidTag) == R.layout.fragment_xuekepu) {
            ListView listView = (ListView) view.findViewById(R.id.lv);
            listView.setAdapter(new Myadapter(getActivity(),R.layout.listview_xuekepu));
        }
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.linearlayoutWenZhen:
                fragmentPropertyManager.showFragment(new FragmentProperty("智能问诊", R.layout.fragment_wenzhen));
                break;
            case R.id.linearlayoutShiPinYiSheng:
                fragmentPropertyManager.showFragment(new FragmentProperty("智能问诊", R.layout.fragment_shipinyisheng));
                break;
            case R.id.linearlayoutXueKePu:
                fragmentPropertyManager.showFragment(new FragmentProperty("智能问诊", R.layout.fragment_xuekepu));
                break;
            case R.id.btn1:
                fragmentPropertyManager.showFragment(new FragmentProperty("症状选择", R.layout.fragment_zhengzhuangxuanze));
                break;
            case R.id.btn2:
                fragmentPropertyManager.showFragment(new FragmentProperty("症状选择", R.layout.fragment_zhengzhuangxuanze));
                break;
            case R.id.btn3:
                fragmentPropertyManager.showFragment(new FragmentProperty("症状选择", R.layout.fragment_zhengzhuangxuanze));
                break;
            case R.id.btn4:
                fragmentPropertyManager.showFragment(new FragmentProperty("症状选择", R.layout.fragment_zhengzhuangxuanze));
                break;
            case R.id.btn5:
                fragmentPropertyManager.showFragment(new FragmentProperty("症状选择", R.layout.fragment_zhengzhuangxuanze));
                break;
            case R.id.xuanze_lin1:
                fragmentPropertyManager.showFragment(new FragmentProperty("疾病介绍", R.layout.fragment_jibingjieshao));
                break;
        }
    }
}